package com.tangkeyon.controller.manage;

import com.tangkeyon.common.Const;
import com.tangkeyon.common.ResponseCode;
import com.tangkeyon.pojo.User;
import com.tangkeyon.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
/**
 * @Author: tangkeyon@gmail.com
 * @Date: 2019/6/18 11:21
 * @Version 1.0
 */
@Controller
@RequestMapping("/manage/order/")
public class OrderManageController {

    @Autowired
    private IOrderService iOrderService;


    @RequestMapping("order_list.do")
    @ResponseBody
    public ResponseCode orderList(HttpSession session, @RequestParam(defaultValue = "10") Integer pageSize,
                                  @RequestParam(defaultValue = "0") Integer pageNum){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if(user !=null){
            if(user.getRole()==Const.Role.ROLE_ADMIN){
                return iOrderService.manageOrderList(pageSize,pageNum);
            }
            return ResponseCode.createByErrorMessage("非管理员登录，没有权限操作");
        }else{
            return ResponseCode.createByErrorMessage("未登录，请先登录");
        }
    }


    @RequestMapping("detail.do")
    @ResponseBody
    public ResponseCode detail(HttpSession session,Long orderId){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if(user !=null){
            if(user.getRole()==Const.Role.ROLE_ADMIN){
                return iOrderService.manageDetail(orderId);
            }
            return ResponseCode.createByErrorMessage("非管理员登录，没有权限操作");
        }else{
            return ResponseCode.createByErrorMessage("未登录，请先登录");
        }
    }

    @RequestMapping("search_order.do")
    @ResponseBody
     public ResponseCode searchOrder(HttpSession session,Long orderNo,@RequestParam(defaultValue = "10") Integer pageSize,
                                     @RequestParam(defaultValue = "0") Integer pageNum){
         User user = (User) session.getAttribute(Const.CURRENT_USER);
         if(user !=null){
             if(user.getRole()==Const.Role.ROLE_ADMIN){
                 return iOrderService.searchOrder(orderNo,pageSize,pageNum);
             }
             return ResponseCode.createByErrorMessage("非管理员登录，没有权限操作");
         }else{
             return ResponseCode.createByErrorMessage("未登录，请先登录");
         }
     }

    @RequestMapping("order_send_goods.do")
    @ResponseBody
    public ResponseCode<String> orderSendGoods(HttpSession session, Long orderNo){
        User user = (User) session.getAttribute(Const.CURRENT_USER);
        if(user !=null){
            if(user.getRole()==Const.Role.ROLE_ADMIN){
                return iOrderService.orderSendGoods(orderNo);
            }
            return ResponseCode.createByErrorMessage("非管理员登录，没有权限操作");
        }else{
            return ResponseCode.createByErrorMessage("未登录，请先登录");
        }
    }
}

















